package top.aicats.pattern.singleton.containerSingleton;

import javafx.beans.binding.ObjectExpression;

import java.awt.*;
import java.util.HashMap;
import java.util.Map;

public class ContainerSingleton {
    private ContainerSingleton() {}

    private static Map<String, Object> ioc = new HashMap<String, Object>();

    public static Object getInstance(String className) {
        synchronized (ioc) {
            if (!ioc.containsKey(className)) {
                Object obj = null;
                try {
                    obj =Class.forName(className).newInstance();
                    ioc.put(className, obj);
                } catch (InstantiationException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                } catch (ClassNotFoundException e) {
                    e.printStackTrace();
                }
            }
            return ioc.get(className);
        }
    }
}
